﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using IFTRUE.CMS.Areas.Admin.Models;

namespace IFTRUE.CMS.Areas.Admin.Controllers
{
    public class AccountController : Controller
    {
        public ActionResult LogOn()
        {
            return View();
        }

        [HttpPost]
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (new LogOnService().LogOn(model.UserName,model.Password))
                {
                    if (Url.IsLocalUrl(returnUrl))
                    {
                        return Redirect(returnUrl);
                    }
                    else
                    {
                        return RedirectToAction("Index", "/Home");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "提供的用户名或密码不正确。");
                }
            }

            // 如果我们进行到这一步时某个地方出错，则重新显示表单
            return View(model);
        }

        public ActionResult User()
        {
            return View();
        }

        [HttpPost]
        public ActionResult User(UserModel model)
        {
           bool bl= new UserService().Save(model);
           if (bl)
               return View();
            return View(model);
        }
    }
}
